package com.cxf.windex.rest.admin;


import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.msg.TableResultResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.ActivityBiz;
import com.cxf.windex.entity.Activity;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: business_needs
 * @description: 活动管理
 * @author: chenxf
 * @create: 2018-10-30 11:12
 **/
@Api(tags = {"村广通[后台] - 活动管理"})
@Controller
@RequestMapping("admin/activity")
public class AdminActivityController extends BaseRestController<ActivityBiz,Activity> {
  @ApiOperation(value = "查询活动", notes = "查询活动")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "limit", value = "记录数 默认10", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "offset", value = "页码 默认 1", required = false, paramType = "query", dataType = "int"),
      @ApiImplicitParam(name = "orderStr", value = "排序 默认desc", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "range", value = "范围 0商家 1村长", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "name", value = "类型名称", required = false, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "type", value = "操作类型", required = false, paramType = "query", dataType = "String"),
  })
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public TableResultResponse<Activity> list(
      @RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1") int offset,
      @RequestParam(defaultValue = "desc") String orderStr,  String name,  @RequestParam(defaultValue = "0")String range,String type) {
    List<Activity> items = baseBiz.list(limit, offset, orderStr,name,range,type);
    PageInfo<Activity> pageInfo = new PageInfo<>(items);
    return new TableResultResponse<Activity>(Integer.parseInt(String.valueOf(pageInfo.getTotal())),
        offset, limit,
        items);
  }

  @ApiOperation(value = "保存活动", notes = "保存活动")
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse save(Activity entity){
    baseBiz.save(entity);
    return new ObjectRestResponse("保存成功").rel(true);
  }
}
